<script type="text/javascript">
	var $awardsadd_content = $("#awardsadd_content");

	$(document).ready(function () {
		var theme = 'fresh';
		$('.field_input').addClass('jqx-input');
		$('.field_input').addClass('field');
		$('.field_input').addClass('jqx-rc-all');

		var awardsadd_save = $("#awardsadd_save");
		var awardsadd_cancel = $("#awardsadd_cancel");
		var awardspost_id = $("#awardspost_id");
		var awardspost_task = $("#awardspost_task");
		var awardspost_gambar = $("#awardspost_gambar");
		var awardspost_gambarname = $("#awardspost_gambarname");
		var awardspost_deskripsi = $("#awardspost_deskripsi");
		var awardspost_link = $("#awardspost_link");


		awardsadd_save.jqxButton({ theme : theme, width : '70px', height : '18px' });
		awardsadd_cancel.jqxButton({ width : '70px' , height : '18px' ,theme : theme });

		awardspost_gambar.fileupload({
			dataType: 'json',
			formData : function(form){
				return [{ name: 'upload', value: '!@#$%^&*())_+=-0876563211' }];
			},
			done: function (e, data){
				var text = "";
				$.each(data.result, function (index, file) {
					text = text + file.name;
					$("#awardspost_gambarname").val(text);
				});
			}
		});
		/* function */
		awardsadd_cancel.click(function(){
			$('#mainpanelcontent').empty();
			$('<img src="./images/loader.gif" style="margin:50px auto auto 390px;">').appendTo('#contents');
			$('#mainpanelcontent').load('index.php/c_awards/awards_load');
		});
		awardsadd_save.click(function(){
			var id = "";
			var image = "";
			var deskripsi = "";
			var link = "";
			var task = "";

			id = awardspost_id.val();

			image = awardspost_gambarname.val();
			deskripsi = awardspost_deskripsi.val();
			link = awardspost_link.val();
			task = awardspost_task.val();

			if(task == ""){
				task = "create";
			}
			$.ajax({
				type : 'POST',
				url : 'index.php/c_awards/awards_save',
				data : {
					id : id,
					image : image,
					deskripsi : deskripsi,
					link : link,
					task : task
				},success : function(msg){
					var result = eval(msg);
					switch(result){
						case 1:
							$('#mainpanelcontent').empty();
							$('<img src="./images/loader.gif" style="margin:50px auto auto 390px;">').appendTo('#contents');
							$('#mainpanelcontent').load('index.php/c_awards/awards_load');
							alert("Data berhasil disimpan");
							break;
						default:
							alert("Data gagal disimpan");
							break;
					}
				}
			});
		});

		<?php
			if(isset($dataDetail)){
		?>
			awardspost_id.val('<?php echo $dataDetail->id; ?>');
			awardspost_gambarname.val('<?php echo $dataDetail->image; ?>');
			awardspost_deskripsi.text('<?php echo $dataDetail->deskripsi; ?>');
			awardspost_link.val('<?php echo $dataDetail->link; ?>');
			awardspost_task.val('update');
		<?php
			}
		?>


	});

</script>
<!-- Begin content -->
<div class="modal_header">
		<span>Awards Form</span>
	</div>
<div class="modal_content">
<div id="awardsadd_content">
	<form action="" method="post"  enctype="multipart/form-data" >
		<input type="hidden" id="awardspost_id">
		<input type="hidden" id="awardspost_task">
		<p>
			<label>Gambar:</label><br/>
			<input type="file" id="awardspost_gambar" name="userfile" style="width:300px" data-url="<?php echo base_url(); ?>upload/upload_img" />
			<input type="hidden" id="awardspost_gambarname">
		</p>
		<br/>
		<p>
			<label>Deskripsi:</label><br/>
			<input type="text" id="awardspost_deskripsi" class="field_input" style="width:300px"/>
		</p>
		<br/>
		<p>
			<label>Link :</label><br/>
			<input type="text" id="awardspost_link" class="field_input" style="width:300px"/>
		</p>
		<br/>
		<br/><br/>
		<p>
			<table align="left">
				<tr align="left">
					<td>
						<div id='awardsadd_save'>
						<img style='float: left; margin: 0px;' src='./images/icons/save.gif' />
						<div style='float: left; margin-left: 4px;'>Simpan</div>
					</div>
					</td>
					<td>
						<div id='awardsadd_cancel'>
						<img style='float: left; margin: 0px;' src='./images/icons/cross.gif' />
						<div style='float: left; margin-left: 4px;'>Cancel</div>
					</div>
					</td>
				</tr>
			</table>
		</p>
		<p>&nbsp;</p>
	</form>
</div>
</div>
<!-- End left column window -->
